<template>
  <div class="bk-empty" @click="$emit('click', $event)">
    <div class="empty-img">
      <img :src="Image">
    </div>
    <p class="empty-desc" v-text="text" />
  </div>
</template>

<script>
export default {
  name: 'empty',
  props: {
    type: {
      default: 'default',
      validator: function (value) {
        return ['default', 'error', 'search'].indexOf(value) !== -1
      }
    },
    desc: {
      type: String,
      default: '描述文字'
    }
  },
  data () {
    return {
      text: ''
    }
  },
  created () {
    this.text = this.desc
  },
  methods: {
    setDesc (desc) {
      if (typeof (desc) === 'string') {
        this.text = desc
      }
    }
  },
  watch: {
    desc (value) {
      this.text = value
    }
  },
  computed: {
    Image () {
      switch (this.type) {
        case 'default':
          return require('./default.png')
        case 'error':
          return require('./error.png')
        case 'search':
          return require('./search.png')
      }
    }
  }
}
</script>

<style scoped lang="less">
  @import "~common/style/variable.less";

  .bk-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 32px 0;
    .empty-img {
      width: 160px;
      height: 160px;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .empty-desc {
      margin-top: 16px;
      padding: 0 60px;
      color: @color-text-l;
      font-size: 14px;
      line-height: 20px;
    }
  }
</style>
